package concurrent.forkjoin;

import java.util.Arrays;
import java.util.concurrent.ForkJoinPool;
import java.util.stream.LongStream;

public class ForkJoinTest {

    public static void main(String[] args) {
        long[] longs = LongStream.range(1, 100_000_000).toArray();
        long startTime = System.currentTimeMillis();

        ForkJoinPool forkJoinPool = new ForkJoinPool();
        Long sum = forkJoinPool.invoke(new SumTask(longs));

        System.out.println("----------------");
        System.out.println(System.currentTimeMillis() - startTime);
        System.out.println(sum);

        startTime = System.currentTimeMillis();
        System.out.println("----------------");
        System.out.println(System.currentTimeMillis() - startTime);
        System.out.println(sum(longs));
    }

    public static long sum(long[] longs) {
        return Arrays.stream(longs).parallel().sum();
    }
}
